#include "Converter.h"
#include <vector>
#include <sstream>
#include <iostream>
#include "ManualHash.h"
#include "BlackList.h"

using namespace std;

Converter::Converter()
{
}

Converter::~Converter()
{
}

vector<uint> Converter::wordToHash(vector<string> vec)
{
	vector<uint> result;
	uint value;
	for(vector<string>::iterator it = vec.begin();it!=vec.end();it++)
	{
		if(!BlackList::isBlackListed(*it))
		{	
			value = ManualHash::ToInteger(*it);
			result.push_back(value);
			cout << "hash: " << value << endl;
		}
	}
	return result;
}

vector<string> Converter::parseQuery(string query)
{
	stringstream ss;
	ss << query;
	vector<string> res;
	string next = "";
	while(ss.good() && !ss.eof())
	{
		ss >> next;
		res.push_back(Converter::ToLower(&next));
		cout << next << endl;
	}
	return res;
}

string Converter::ToLower(const string* word)
{
	string s = "";
	char* aux = const_cast<char *>(word->c_str());
	for(size_t i = 0; i < word->size(); i++)
		s += tolower(aux[i]);
	return s;
}